package bancosys.tec.security.impl.services.incluir;

import jmine.tec.services.annotations.Execution;
import jmine.tec.services.annotations.Input;
import jmine.tec.services.annotations.ServiceImplementor;
import jmine.tec.services.api.ActionsEnum;
import bancosys.tec.security.impl.domain.Credential;
import bancosys.tec.security.impl.domain.Group;
import bancosys.tec.security.impl.domain.MetaCredential;

/**
 * Serviço que, dada uma Meta Credencial, percorre sua lista de credenciais, associando-as ao grupo dado.
 * 
 * @author seiti
 * @created Oct 11, 2010
 */
@ServiceImplementor(action = ActionsEnum.INCLUIR)
public class GroupMetaCredentialService {

	public static final String META_CREDENTIAL = "Meta Credencial";
	
	public static final String GROUP = "Grupo";
	
	private MetaCredential metaCredential;
	
	private Group group;
	
	/**
	 * Realiza o serviço 
	 */
	@Execution
	public void execute() {
 		for (Credential credential : this.metaCredential.getCredentials()) {
 			this.group.addCredential(credential);
 		}
 		this.group.getPersister().save();
	}

	/**
	 * @param metaCredential to set
	 */
	@Input(fieldName = META_CREDENTIAL)
	public void setMetaCredential(MetaCredential metaCredential) {
		this.metaCredential = metaCredential;
	}
	
	/**
	 * @param group to set
	 */
	@Input(fieldName = GROUP)
	public void setGroup(Group group) {
		this.group = group;
	}
}